package com.bbs.controller;

import com.bbs.domain.ResultInfo;
import com.bbs.service.NiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class NiceController {
    @Autowired
    private NiceService niceService;

    @RequestMapping("/like")
    @ResponseBody
    public ResultInfo niceUp(Integer pid, HttpSession session){
        ResultInfo resultInfo = new ResultInfo();
        if (pid == null) {
            resultInfo.setCode("1");
            resultInfo.setMsg("pid 为空");
            return resultInfo;
        }
        Integer userId = (Integer) session.getAttribute("uid");
        if (userId == null) {
            resultInfo.setCode("1");
            resultInfo.setMsg("请先登录");
            return resultInfo;
        }

        int linkCount = niceService.updateNice(pid, userId);

        resultInfo.setData(String.valueOf(linkCount));
        return resultInfo;
    }


}
